}
}
- pub fn bin_target(name: &str, src_path: &Path, profile: &Profile) -> Target {
+ pub fn bin_target(name: &str, src_path: &Path, profile: &Profile,
+ metadata: Option<Metadata>) -> Target {
Target {
kind: BinTarget,
name: name.to_string(),
src_path: src_path.clone(),
profile: profile.clone(),
- metadata: None
+ metadata: metadata,
}
}
name: name.to_string(),
src_path: src_path.clone(),
profile: profile.clone(),
- metadata: None
+ metadata: None,
}
}
}
fn bin_targets(dst: &mut Vec<Target>, bins: &[TomlBinTarget],
- dep: TestDep, default: |&TomlBinTarget| -> String) {
+ dep: TestDep, metadata: &Metadata,
+ default: |&TomlBinTarget| -> String) {
for bin in bins.iter() {
let path = bin.path.clone().unwrap_or_else(|| {
TomlString(default(bin))
});
for profile in target_profiles(bin, dep).iter() {
+ let metadata = if profile.is_test() {
+ // Make sure that the name of this test executable doesn't
+ // conflicts with a library that has the same name and is
+ // being tested
+ let mut metadata = metadata.clone();
+ metadata.mix(&format!("bin-{}", bin.name));
+ Some(metadata)
+ } else {
+ None
+ };
dst.push(Target::bin_target(bin.name.as_slice(),
&path.to_path(),
- profile));
+ profile,
+ metadata));
}
}
}
fn example_targets(dst: &mut Vec<Target>, examples: &[TomlExampleTarget],
- default: |&TomlExampleTarget| -> String) {
+ default: |&TomlExampleTarget| -> String) {
for ex in examples.iter() {
let path = ex.path.clone().unwrap_or_else(|| TomlString(default(ex)));
TomlString(default(test))
});
- let profile = &Profile::default_test();
// make sure this metadata is different from any same-named libs.
let mut metadata = metadata.clone();
- metadata.mix(&format!("test-{}", test.name.as_slice()));
+ metadata.mix(&format!("test-{}", test.name));
+ let profile = &Profile::default_test();
dst.push(Target::test_target(test.name.as_slice(),
&path.to_path(),
profile,
match (libs, bins) {
([_, ..], [_, ..]) => {
lib_targets(&mut ret, libs, Needed, metadata);
- bin_targets(&mut ret, bins, test_dep,
+ bin_targets(&mut ret, bins, test_dep, metadata,
|bin| format!("src/bin/{}.rs", bin.name));
},
([_, ..], []) => {
lib_targets(&mut ret, libs, test_dep, metadata);
},
([], [_, ..]) => {
- bin_targets(&mut ret, bins, test_dep,
+ bin_targets(&mut ret, bins, test_dep, metadata,
|bin| format!("src/{}.rs", bin.name));
},
([], []) => ()
test test_hello ... ok\n\n\
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n",
COMPILING, p.root().display())));
-
- assert_that(&p.bin("test/foo"), existing_file());
})
test!(many_similar_names {
0 ignored; 0 measured\n\n",
COMPILING, p.root().display(),
sep = path::SEP)));
-
- assert_that(&p.bin("test/foo"), existing_file());
})
test!(test_with_lib_dep {
compiling = COMPILING,
dir = p.root().display()).as_slice()));
})
+
+test!(bin_there_for_integration {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/main.rs", "
+ fn main() { std::os::set_exit_status(1); }
+ #[test] fn main_test() {}
+ ")
+ .file("tests/foo.rs", r#"
+ use std::io::Command;
+ #[test]
+ fn test_test() {
+ let status = Command::new("target/test/foo").status().unwrap();
+ assert!(status.matches_exit_status(1));
+ }
+ "#);
+
+ let output = p.cargo_process("cargo-test").exec_with_output().assert();
+ let output = str::from_utf8(output.output.as_slice()).assert();
+ assert!(output.contains("main_test ... ok"), "no main_test\n{}", output);
+ assert!(output.contains("test_test ... ok"), "no test_test\n{}", output);
+})